package com.jeesite.modules.billnorecord.web;

import java.util.List;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jeesite.common.config.Global;
import com.jeesite.common.entity.Page;
import com.jeesite.common.web.BaseController;
import com.jeesite.modules.billnorecord.entity.BillNoRecord;
import com.jeesite.modules.billnorecord.service.BillNoRecordService;

/**
 * 单据编码记录表Controller
 * @author 码脑洞
 * @version 2025-04-13
 */
@Controller
@RequestMapping(value = "${adminPath}/billnorecord/billNoRecord")
public class BillNoRecordController extends BaseController {

	@Autowired
	private BillNoRecordService billNoRecordService;
	
	/**
	 * 获取数据
	 */
	@ModelAttribute
	public BillNoRecord get(Long autoId, boolean isNewRecord) {
		return billNoRecordService.get(autoId, isNewRecord);
	}
	
	/**
	 * 查询列表
	 */
	@RequiresPermissions("billnorecord:billNoRecord:view")
	@RequestMapping(value = {"list", ""})
	public String list(BillNoRecord billNoRecord, Model model) {
		model.addAttribute("billNoRecord", billNoRecord);
		return "modules/billnorecord/billNoRecordList";
	}
	
	/**
	 * 查询列表数据
	 */
	@RequiresPermissions("billnorecord:billNoRecord:view")
	@RequestMapping(value = "listData")
	@ResponseBody
	public Page<BillNoRecord> listData(BillNoRecord billNoRecord, HttpServletRequest request, HttpServletResponse response) {
		billNoRecord.setPage(new Page<>(request, response));
		Page<BillNoRecord> page = billNoRecordService.findPage(billNoRecord);
		return page;
	}

	/**
	 * 查看编辑表单
	 */
	@RequiresPermissions("billnorecord:billNoRecord:view")
	@RequestMapping(value = "form")
	public String form(BillNoRecord billNoRecord, Model model) {
		model.addAttribute("billNoRecord", billNoRecord);
		return "modules/billnorecord/billNoRecordForm";
	}

	/**
	 * 保存数据
	 */
	@RequiresPermissions("billnorecord:billNoRecord:edit")
	@PostMapping(value = "save")
	@ResponseBody
	public String save(@Validated BillNoRecord billNoRecord) {
		billNoRecordService.save(billNoRecord);
		return renderResult(Global.TRUE, text("保存单据编码记录表成功！"));
	}
	
}